//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Copyright 2012 Microsoft Corporation. All Rights Reserved
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.   
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

namespace Preflight.Client
{
    using System.Collections.Generic;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Converters;
    using ServiceModel.Contract;

    public static class Build
    {
        public static string PreflightCheckJson()
        {
            var check = Check();
            var settings = new JsonSerializerSettings();
            settings.Converters.Add(new StringEnumConverter());
            return Newtonsoft.Json.JsonConvert.SerializeObject(check, settings);
        }

        public static PreflightCheck Check()
        {
            return new PreflightCheck
            {
                Description = DescriptionA(),
                Passed = true,
                Categories = new List<Category>
                        {
                            CategoryA(),
                            CategoryB()
                        }
            };
        }

        public static Description DescriptionA()
        {
            return new Description
            {
                Name = "Application A",
                Category = "Sample Applications",
                Version = "1.0.0.0"
            };
        }

        public static Category CategoryA()
        {
            return new Category
            {
                Name = "Core Dependencies",
                Verifications = new List<Verification>
                    {
                        VerificationWithMessageC(),
                        VerificationWithMessagesAAndB()
                    }
            };
        }

        public static Category CategoryB()
        {
            return new Category
            {
                Name = "Non-Critical",
                Verifications = new List<Verification>
                    {
                        VerificationWithMessagesAAndB()
                    }
            };
        }

        public static Verification VerificationWithMessagesAAndB()
        {
            return new Verification
            {
                Name = "Core Database",
                Passed = true,
                Messages = new List<PreflightMessage>
                        {
                            MessageA(),
                            MessageB()
                        }
            };
        }

        public static Verification VerificationWithMessageC()
        {
            return new Verification
            {
                Name = "File Permissions",
                Passed = true,
                Messages = new List<PreflightMessage>
                        {
                            MessageC()
                        }
            };
        }

        public static PreflightMessage MessageA()
        {
            return new PreflightMessage { Content = "Failed to connect to ACME Database", Type = PreflightMessageType.Error };
        }

        public static PreflightMessage MessageB()
        {
            return new PreflightMessage { Content = "Verifying Connection to ACME Database", Type = PreflightMessageType.Information };
        }

        public static PreflightMessage MessageC()
        {
            return new PreflightMessage { Content = "Verifying access to root drive", Type = PreflightMessageType.Information };
        }
    }
}
